//
//  HNSH_ChatOpenRedDetailCell.m
//  NongYe
//
//  Created by 李宇廷 on 2023/2/6.
//

#import "HNSH_ChatOpenRedDetailCell.h"

@interface HNSH_ChatOpenRedDetailCell ()

/* headerImgV */
@property (nonatomic, strong) UIImageView *headerImgV;
/* nameLabel */
@property (nonatomic, strong) UILabel *nameLabel;
/* timeLabel */
@property (nonatomic, strong) UILabel *timeLabel;
/* moneyLabel */
@property (nonatomic, strong) UILabel *moneyLabel;

/* statuImgV */
@property (nonatomic, strong) UIImageView *statuImgV;
/* statuLabel */
@property (nonatomic, strong) UILabel *statuLabel;

/* lineView */
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HNSH_ChatOpenRedDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self configView];
    }
    return self;
}

- (void)configView {
    [self addAllViews];
    [self addAllLayout];
}

- (void)setModel:(NYChatRedDetailOpenListItemModel *)model {
    [self.headerImgV sd_setImageWithURL:[NSURL URLWithString:model.avatar_url] placeholderImage:[UIImage imageNamed:@"login_home_center_icon"]];
    self.nameLabel.text = model.nickname;
    self.timeLabel.text = model.open_time_text;
    self.moneyLabel.text = model.amount_text;
    self.statuLabel.hidden = self.statuImgV.hidden = !model.luckiest_draw;
}

- (void)addAllViews {
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.headerImgV];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.moneyLabel];
    [self.contentView addSubview:self.statuLabel];
    [self.contentView addSubview:self.statuImgV];
    [self.contentView addSubview:self.lineView];
}

- (void)addAllLayout {
    [self.headerImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.mas_equalTo(16);
        make.width.height.mas_equalTo(40);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(68);
        make.top.mas_equalTo(12);
        make.height.mas_equalTo(20);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(68);
        make.top.mas_equalTo(32);
        make.height.mas_equalTo(20);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(12);
        make.height.mas_equalTo(20);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    [self.statuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(32);
        make.height.mas_equalTo(20);
    }];
    [self.statuImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.statuLabel.mas_left).offset(-4);
        make.top.mas_equalTo(32);
        make.height.width.mas_equalTo(20);
    }];
}

#pragma mark lazy
- (UIImageView *)headerImgV {
    if (!_headerImgV) {
        _headerImgV = [[UIImageView alloc]init];
        _headerImgV.backgroundColor = [UIColor orangeColor];
        _headerImgV.layer.cornerRadius = 4.0f;
        _headerImgV.layer.masksToBounds = YES;
    }
    return _headerImgV;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"沃岩";
        _nameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
        _nameLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _nameLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.text = @"15:53";
        _timeLabel.textColor = [UIColor colorWithHexString:@"#999999"];
        _timeLabel.font = [UIFont systemFontOfSize:14];
    }
    return _timeLabel;
}

- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc]init];
        _moneyLabel.text = @"1.05购物值";
        _moneyLabel.textColor = [UIColor colorWithHexString:@"#333333"];
        _moneyLabel.font = [UIFont systemFontOfSize:14];
    }
    return _moneyLabel;
}

- (UIView *)lineView {
    if (!_lineView ) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#F3F3F3"];
    }
    return _lineView;
}

- (UIImageView *)statuImgV {
    if (!_statuImgV) {
        _statuImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"chat_open_red_detail_icon_zuijia"]];
    }
    return _statuImgV;
}

- (UILabel *)statuLabel {
    if (!_statuLabel) {
        _statuLabel = [[UILabel alloc]init];
        _statuLabel.text = @"手气最佳";
        _statuLabel.textColor = [UIColor colorWithHexString:@"#FFA652"];
        _statuLabel.font = [UIFont systemFontOfSize:14];
    }
    return _statuLabel;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
